<%@ page language="C#" autoeventwireup="true" masterpagefile="../../masterpages/Dialog.master" codebehind="GenerateVoucher.aspx.cs" inherits="UCommerce.Web.UI.Marketing.Dialogs.GenerateVoucher" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>
<%@ Import Namespace="UCommerce.Web.UI.Marketing.Dialogs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            var prefix;
            var suffix;
            var lengthOfCode;

            $("#PrefixTextBox, #SuffixTextBox, #CodeLengthTextBox").keyup(function () {
                prefix = $("#PrefixTextBox").val();
                suffix = $("#SuffixTextBox").val();
                lengthOfCode = $("#CodeLengthTextBox").val();
                join();
            })
            function generateCode() {
                var code = "";
                for (var i = 0; i < lengthOfCode; i++) {
                    code += "X";
                }
                return code;
            }
            function seperatorPrefix() {
                var sepPre = "";
                if (prefix != "") {
                    sepPre = "-";
                }
                return sepPre;
            }
            function seperatorSuffix() {
                var sepSuf = "";
                if (suffix != "") {
                    sepSuf = "-";
                }
                return sepSuf;
            }

            function join() {
                $("#lblExample").text(prefix + seperatorPrefix() + generateCode() + seperatorSuffix() + suffix);
            }

        });
</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeaderLabel" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentArea" runat="server">
    <div class="propertyPane">
		<table colspan="2" align="center" >
		<tr>
			<td style="vertical-align:top; width:45%" colspan="1">
				<p>
				<FieldSet>
				<Legend><%= GetLocalResourceObject("Manual.Text") %></Legend>
				<table colspan="3" style="height:200px;">
					<tr>				
					<td style="vertical-align:top; height:20px;" colspan="1"><%= GetLocalResourceObject("Code.Text") %></td>
						<td style="vertical-align:top; height:20px;" colspan="2">
							<asp:TextBox width="70px" runat="server" id="CodeTextBox" 
								MaxLength="20" />
							<asp:RequiredFieldValidator id="ManualCodeValidator" runat="server" 
								ValidationGroup="ManualVoucherGroup"
								ControlToValidate="CodeTextBox" Text="*" />
							<asp:CustomValidator id="ManualUniqueVoucherCodeValidator" runat="server" 
							OnServerValidate="UniqueVoucherCode_OnServerValidate"  
							ControlToValidate="CodeTextBox" 
							ValidationGroup="ManualVoucherGroup"
							Text="*"/>
						</td>
					</tr>
					<tr>
						<td style="vertical-align:top; height:20px;" colspan="1"><%= GetLocalResourceObject("MaxUses.Text") %></td>
						<td style="vertical-align:top; height:20px;" colspan="2">
							<asp:TextBox width="70px" runat="server" 
								ID="MaxUseTextBox" Text="1" />
							<asp:RequiredFieldValidator id="ManualMaxUseValidator" runat="server" 
							 ValidationGroup="ManualVoucherGroup" 
							 ControlToValidate="MaxUseTextBox" Text="*" />
					<asp:RegularExpressionValidator ID="ManualRegexMaxUse" runat="server"     
								 ValidationGroup="ManualVoucherGroup"
								 InitialValue=""
								 Text="*"
								 ControlToValidate="MaxUseTextBox"     
								 ValidationExpression="^\d+$" />
						</td>
					</tr>
					<tr>
					<td colspan="3">
						<asp:ValidationSummary ID="ValidationSummary1"
						ValidationGroup="ManualVoucherGroup"
						DisplayMode="BulletList"
						EnableClientScript="true"
						runat="server" />
					</td>
					</tr>
					<tr>					
					<td style="vertical-align:bottom" colspan="1">
						<asp:Button id="AddManualButton" runat="server" 
							OnClick="AddManualVoucherButton" validationgroup="ManualVoucherGroup" />
						</td>
					</tr>
				</table>
				</FieldSet>
				</p>
			</td>
			<td style="vertical-align:top;" colspan="1">
				<div>
				<FieldSet>
				<Legend><%= GetLocalResourceObject("Generate.Text") %></Legend>
				<table colspan="4" style="height:200px; width:100%">
					<tr>
						<td style="vertical-align:top; height:20px; width:100px;" colspan="1"><%= GetLocalResourceObject("Prefix.Text") %></td>
						<td style="vertical-align:top; height:20px;" colspan="1">
							<asp:TextBox runat="server" width="70px" ID="PrefixTextBox" 
								ClientID="PrefixTextBox" />
						</td>
					</tr>
					<tr>
						<td style="vertical-align:top; height:20px; width:100px;" colspan="1"><%= GetLocalResourceObject("Suffix.Text") %></td>
						<td style="vertical-align:top; height:20px;" colspan="1">
							<asp:TextBox runat="server" width="70px" ID="SuffixTextBox" 
								ClientID="SuffixTextBox" />
						</td>
					</tr>
					<tr>				
						<td style="vertical-align:top; height:20px; width:100px;" colspan="1"><%= GetLocalResourceObject("LengthOfCode.Text") %></td>
						<td style="vertical-align:top; height:20px;" colspan="3">
							<asp:TextBox runat="server" width="70px" id="CodeLengthTextBox" Text="6" />
							<asp:RangeValidator id="CodeLengthRangeValidator" runat="server"
								  ControlToValidate="CodeLengthTextBox"
								  ValidationGroup="GenerateVoucherGroup"
								  Type="Integer"
								  MinimumValue="6"
								  MaximumValue="20" Text="*" />
							<asp:RequiredFieldValidator id="GenerateCodeLengthValidator" runat="server" 
								 ValidationGroup="GenerateVoucherGroup"
								 ControlToValidate="CodeLengthTextBox" Text="*" />
							<asp:RegularExpressionValidator id="GenerateRegexLengthValidator" runat="server"     
								 ValidationGroup="GenerateVoucherGroup" 
								 ControlToValidate="CodeLengthTextBox"  
								 ValidationExpression="^\d+$" InitialValue="" Text="*" />					
						</td>
					</tr>
					<tr>
						<td style="vertical-align:top; height:20px; width:100px;" colspan="1"><%= GetLocalResourceObject("MaxUses.Text") %></td>
						<td style="vertical-align:top; height:20px;" colspan="3">
							<asp:TextBox runat="server" width="70px" id="GenerateMaxUseTextBox" Text="1" />
							<asp:RequiredFieldValidator id="GenerateMaxUseValidator" runat="server" 
								 ValidationGroup="GenerateVoucherGroup"
								 ControlToValidate="GenerateMaxUseTextBox" Text="*" />
							<asp:RegularExpressionValidator id="GenerateRegexMaxUseValidator" runat="server"     
								 ValidationGroup="GenerateVoucherGroup"
								 ControlToValidate="GenerateMaxUseTextBox"   
								 Text="*"  
								 InitialValue=""
								 ValidationExpression="^\d+$" />
						</td>
					</tr>
					<tr>				
						<td style="vertical-align:top; height:20px; width:100px;" colspan="1"><%= GetLocalResourceObject("NumberToGen.Text") %></td>
						<td style="vertical-align:top; height:20px;" colspan="3">
							<asp:TextBox runat="server" width="70px" id="NumberToGenerateTextBox" 
								Text="1000" />
							<asp:RequiredFieldValidator id="GenerateNumberToGenValidator" runat="server" 
								ValidationGroup="GenerateVoucherGroup"
								ControlToValidate="NumberToGenerateTextBox" Text="*" />
							<asp:RegularExpressionValidator id="GenerateRegexNumberValidator" runat="server"     
								 ValidationGroup="GenerateVoucherGroup" 
								 ControlToValidate="NumberToGenerateTextBox"  
								 Text="*"   
								 ValidationExpression="^\d+$" />
						</td>
						</td>
					</tr>
					<tr>
						<td colspan="1">
						<%= GetLocalResourceObject("Example.Text") %>
						</td>
						<td colspan="3">
						<asp:Label width="80px" id="lblExample" Text="XXXXXX" runat="server" ></asp:Label>
						</td>
					</tr>
					<tr>
					<td colspan="4">
						<asp:ValidationSummary ID="ValidationSummary2"
						ValidationGroup="GenerateVoucherGroup"
						DisplayMode="BulletList"
						EnableClientScript="true"
						runat="server" />
					</td>
					</tr>
					<tr>
						<td style="vertical-align:bottom;" colspan="2">
							<asp:Button runat="server" ID="AddGenerateButton" 
								OnClick="AddGenerateVoucherButton" ValidationGroup="GenerateVoucherGroup" 
								Text="Add" />
						</td>
					</tr>
				</table>
				</FieldSet>
			</div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<fieldset>
				<legend>
				<%= GetLocalResourceObject("Showing.Text") %>
					<%= VoucherCodesToShow() %> 
					<%= GetLocalResourceObject("Of.Text") %> 
					<%= VoucherCodesTotal() %>
				</legend>
					<div style="height:230px; overflow:auto; ">
					<asp:Repeater ID="VoucherCodeRepeater" runat="server">
						<headertemplate>
							<table class="voucherCode">
								<tr>
									<th style="width:300px;">
										<asp:Localize ID="Localize2" runat="server" meta:resourcekey="Code"></asp:Localize>
									</th>
									<th style="width:90px;">
										<asp:Localize ID="Localize3" runat="server" meta:resourcekey="NumberUsed"></asp:Localize>
									</th>
									<th style="width:70px;">
										<asp:Localize ID="Localize4" runat="server" meta:resourcekey="MaxUses"></asp:Localize>
									</th>
									<th style="width:20px;">
									</th>
								</tr>
						</HeaderTemplate>
						<itemtemplate>
							<tr>
								<td style="width:300px;">
									<%# Eval("Code") %>
								</td>
								<td style="width:90px;">
									<%# Eval("NumberUsed") %>
								</td>
								<td style="width:70px;">
									<%# Eval("MaxUses") %>
								</td>
								<td style="text-align:right; width:20px;">
									<asp:ImageButton id="DeleteTargetButton" runat="server" 
										commandargument="<%# ((VoucherPlaceHolder)Container.DataItem).Code %>" 
										imageurl="../../Images/ui/cross.png" 
										oncommand="DeleteVoucherCode_Command" />
									<br />
								</td>
							</tr>
						</ItemTemplate>
						<footertemplate>
						 </table>
						</FooterTemplate>
					</asp:Repeater>
					</div>
				</fieldset>
			</td>
		</tr>
		</table>
	</div>
    <div style="margin:10px;">
		<asp:Button id="SaveButton" runat="server" onclick="SaveButton_Click" text="Save" />
		<em><%= GetLocalResourceObject("Or.Text") %></em>
		<a href="#" onclick="UCommerceClientMgr.closeModalWindow();" style="color: blue; cursor: hand">
			<%= GetLocalResourceObject("Cancel.Text") %>
		</a>
    </div>

</asp:Content>